package com.tgu.home_action.controller;

import com.tgu.home_action.pojo.LargeScreenData;
import com.tgu.home_action.pojo.Place;
import com.tgu.home_action.pojo.ResponseData;
import com.tgu.home_action.pojo.state.ResponseState;
import com.tgu.home_action.service.LargeScreenService;
import com.tgu.home_action.service.utils.WXService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.Map;

@Api(tags = "大屏端")
@RestController
@RequestMapping("/largeScreen")
public class LargeScreenController {
    @Autowired
    private WXService wxService;
    @Autowired
    private LargeScreenService largeScreenService;

    @ApiOperation("获取二维码")
    @GetMapping("/unlimited")
    public void getUnlimited(@RequestParam Integer caseId, HttpServletResponse response) {
        response.setContentType("image/jpeg");
        wxService.getUnlimited(caseId, response);
    }

    @ApiOperation("获取数据")
    @GetMapping
    public ResponseData<LargeScreenData> getData(Place place){
        try {
            return largeScreenService.getData(place);
        } catch (ParseException e) {
            return new ResponseData<>(ResponseState.ERROR.getMessage(), ResponseState.ERROR.getValue());
        }
    }
}
